<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改党员基本信息')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-member-edit" th:object="${member}">
            <input name="memberId" th:field="*{memberId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">党员姓名：</label>
                <div class="col-sm-8">
                    <input name="memberName" th:field="*{memberName}" class="form-control" type="text" maxlength="30" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">身份证号：</label>
                <div class="col-sm-8">
                    <input name="card" th:field="*{card}" class="form-control" type="text" maxlength="18" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">出生年月日：</label>
                <div class="col-sm-8">
                    <!-- <input name="birthday" th:field="*{birthday}" class="form-control" type="text" required> -->
                    <input type="text" maxlength="10" name="birthday" th:field="*{birthday}" class="form-control time-input"  required placeholder="请填写出生年月日">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">政治生日：</label>
                <div class="col-sm-8">
                    <!-- <input name="partyBirthday" th:field="*{partyBirthday}" class="form-control" type="text" required> -->
                    <input type="text" maxlength="10" name="partyBirthday" th:field="*{partyBirthday}" class="form-control time-input"  required placeholder="请填写政治生日">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">行政级别：</label>
                <div class="col-sm-8">
                    <select name="adminLevel" class="form-control m-b" th:with="type=${@dict.getType('admin_level')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{adminLevel}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">党内职务：</label>
                <div class="col-sm-8">
                    <select name="partyDuty" class="form-control m-b" th:with="type=${@dict.getType('party_duty')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{partyDuty}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">所属支部：</label>
                <div class="col-sm-8">
                    <!-- <input name="orgId" th:field="*{orgId}" class="form-control" type="text" required> -->
                    <select id="orgZb" class="form-control select2-multiple" name="orgId" th:field="*{orgId}">
						<option th:each="orgZb:${orgZbs}" th:value="${orgZb.orgId}"
							th:text="${orgZb.orgName}"></option>
					</select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属党小组：</label>
                <div class="col-sm-8">
                    <!-- <input name="orgGid" th:field="*{orgGid}" class="form-control" type="text"> -->
                    <select id="orgDxz" class="form-control select2-multiple" name="orgGid" th:field="*{orgGid}">
						<option value="">请选择</option>
						<option th:each="orgDxz:${orgDxzs}" th:value="${orgDxz.orgId}"
							th:text="${orgDxz.orgName}"></option>
					</select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/member";
        $("#form-member-edit").validate({
            focusCleanup: true,
            rules:{
                card:{
                    isIdCardNo:true,
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-member-edit').serialize());
            }
        }
        
        $(function() {
			
           $('#orgZb').select2({
               placeholder: "请选择党支部",
               allowClear: true
           });
           $('#orgDxz').select2({
               placeholder: "请选择党小组",
               allowClear: true
           });
           
           
           jQuery.validator.addMethod("isIdCardNo", function (value, element){
		        return this.optional(element) || isIdCardNo(value);
		    },"请正确输入您的身份证号码");
			
           function isIdCardNo(num) {
               var factorArr = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5,8, 4, 2, 1];
               var parityBit = ["1", "0", "X", "9", "8", "7", "6", "5", "4","3", "2"];
               var varArray= [];
               var lngProduct = 0;
               var intCheckDigit;
               var intStrLen = num.length;
               var idNumber= num;
               //initialize
               if(intStrLen !== 18) {
                   return false;
               }
               // check andset value
               for (i = 0;i < intStrLen; i++) {
                   varArray[i] = idNumber.charAt(i);
                   if ((varArray[i] < '0' || varArray[i]> '9') && (i !== 17)){
                       return false;
                   } else if (i < 17) {
                       varArray[i] = varArray[i] * factorArr[i];
                   }
               }

               if(intStrLen === 18) {
                   //check date
                   var date8 = idNumber.substring(6, 14);
                   if (!isDate8(date8)) {
                       return false;
                   }
                   // calculate the sum of the products
                   for (i = 0; i < 17; i++) {
                       lngProduct = lngProduct + varArray[i];
                   }
                   // calculate the check digit
                   intCheckDigit = parityBit[lngProduct % 11];
                   // check last digit
                   if (varArray[17] != intCheckDigit) {
                       return false;
                   }
               }else{
                   return false;
               }
               return true;
           }

           
           
           function isDate8(sDate) {
               if(!/^[0-9]{8}$/.test(sDate)) {
                   return false;
               }
               var year,month, day;
               year =sDate.substring(0, 4);
               month =sDate.substring(4, 6);
               day =sDate.substring(6, 8);
               var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31];
               if (year< 1700 || year > 2500) {
                   return false;
               }
               if (((year %4 == 0) && (year % 100 != 0)) ||(year % 400 == 0)) {
                   iaMonthDays[1] = 29;
               }
               if (month< 1 || month > 12) {
                   return false;
               }
               return !(day < 1 || day > iaMonthDays[month - 1]);
           }

           
           
           
           
       })
        
    </script>
</body>
</html>